package com.eas.ereceipt.app;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockFragment;
import com.eas.ereceipt.R;
import com.eas.ereceipt.adapter.ListReceiptAdapter;
import com.eas.ereceipt.bean.Receipt;
import com.eas.ereceipt.util.FakeData;

public class ListReceiptFragment extends SherlockFragment{
	private ListView lvReceipts;
	private ListReceiptAdapter adapter;
	

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View root = inflater.inflate(R.layout.fragment_list_receipt, container, false);
		
		lvReceipts = (ListView) root.findViewById(R.id.lvReceipts);
		adapter = new ListReceiptAdapter(getSherlockActivity(), FakeData.generateReceipt());
		lvReceipts.setAdapter(adapter);
		lvReceipts.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapter, View v, int pos,
					long id) {
				Receipt r = (Receipt) ListReceiptFragment.this.adapter.getItem(pos);
				switch (r.getState()) {
				case Receipt.STATE_OK:
					startActivity(new Intent(getActivity(), ReceiptDetailActivity.class));
					break;
				case Receipt.STATE_PROCESSING:
					Toast.makeText(getActivity(), "Receipt in processing", Toast.LENGTH_SHORT).show();
					break;
				case Receipt.STATE_UPLOADING:
					Toast.makeText(getActivity(), "Uploading receipt", Toast.LENGTH_SHORT).show();
					break;

				default:
					break;
				}
			}
		});
		
		return root;
	}
	
	/*@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setupActionBar();
	}
	
	private void setupActionBar(){
		SlidingFragmentActivity parrent = (SlidingFragmentActivity) getActivity();
		ActionBar bar = parrent.getSupportActionBar();
		View v = parrent.getLayoutInflater().inflate(R.layout.business_ab, null);
		bar.setCustomView(v);
		TextView tvTitle = (TextView) v.findViewById(R.id.tvTitle);
		tvTitle.setText(R.string.item_business_title);
		
		btnRefresh = (ImageButton) v.findViewById(R.id.btnRefresh);
		btnNew = (ImageButton) v.findViewById(R.id.btnNewReceipt);
		
		btnRefresh.setOnClickListener(this);
		btnNew.setOnClickListener(this);
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnRefresh:
			
			break;
		case R.id.btnNewReceipt:
			startActivity(new Intent(getActivity(), NewReceiptActivity.class));
			break;

		default:
			break;
		}
	}*/

}
